package com.zz.parkingsystem.controller.admin;

import com.zz.parkingsystem.entity.OrderItem;
import com.zz.parkingsystem.service.ExceptionOrderService;
import com.zz.parkingsystem.service.OrderItemService;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import com.zz.parkingsystem.vo.OrderItemVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author ：zzz
 * @date ：Created in 2022/9/7 20:52
 * @description：aaa
 */
@RestController
@RequestMapping("admin/PaymentStatistics")
public class AdminPaymentStatistics {
    @Resource
    private OrderItemService orderItemService;
    @Resource
    private ExceptionOrderService exceptionOrderService;
    //根据正常订单减去异常订单算出主动支付的订单总数
    //小心表中数据问题
    @GetMapping("/getInitiativeToPay")
    public Result getInitiativeToPay(){
        //总订单
        List<OrderItem> ordersTotal = orderItemService.getOrdersTotal();
        //异常订单总数
        Integer numberOfAbnormal = exceptionOrderService.getNumberOfAbnormal();
        //支付了的订单
        List<OrderItemVo> paymentAmount = orderItemService.getPaymentAmount();
        Integer size = ordersTotal.size();
        Integer size1 = numberOfAbnormal;
        //主动支付的订单总数
        Integer count= paymentAmount.size();
        Integer count3 = 0;
        Integer count4 = 0;
        for (OrderItemVo orderItemVo : paymentAmount) {
            //算微信支付的总额
            if (orderItemVo.getPtType() == 0){
                Integer oiAmount = orderItemVo.getOiAmount();
                count3 +=  oiAmount;
            }else{
                //算支付宝支付的总额
                Integer aa = orderItemVo.getOiAmount();
                count4+=aa;
            }
        }
        HashMap<Object, Object> map = new HashMap<>();
        map.put("coun",count);
        map.put("count3",count3);
        map.put("count4",count4);
        return ResultGenerator.genSuccessResult(map);
    }
}
